package com.pocket.insight.base.sql.dialect;

import com.google.common.base.Strings;
import com.pocket.insight.base.mql.TypedVal;
import com.pocket.insight.base.sql.Dialect;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 描述：
 *
 * @author shuize
 * @create 2024/12/9
 */
public class MongoDialect implements Dialect<Object> {

    public static String DATABASE_COLLECTION_SPLIT = "_ID_ID_";

    /********************************* 1. 标识符差异配置 *********************************/
    @Override
    public String escString(String s) {
        return null;
    }

    @Override
    public String getLeftQuoteChar() {
        return "";
    }

    @Override
    public String getRightQuoteChar() {
        return "";
    }

    @Override
    public String quoteString(String s) {
        return this.quoteSingle(s);
    }

    public String quoteSingle(String entity) {
        return entity;
    }

    @Override
    public String quotePath(List<String> paths) {
        return paths.stream().collect(Collectors.joining(DATABASE_COLLECTION_SPLIT));
    }

    @Override
    public String quotePathName(String pathName) {
        return String.format("\"%s\"", pathName);
    }

    @Override
    public String quoteTableName(String tableName) {
        return tableName;
    }

    @Override
    public String quoteTableNameWithoutSplit(String tableName) {
        return tableName;
    }

    @Override
    public String quoteFieldName(String fieldName) {
        return "$" + fieldName;
    }

    @Override
    public String quoteFieldName(String tableName, String fieldName, String baseTableAlias) {
        return this.quoteFieldName(parseMongoFieldName(tableName, fieldName, baseTableAlias));
    }

    @Override
    public String quoteEntity(String entity) {
        return entity;
    }

    @Override
    public String unquoteSingleEntity(String s) {
        return null;
    }

    @Override
    public String quoteAliasName(String aliasName) {
        return aliasName;
    }

    @Override
    public String quoteOrderByAliasName(TypedVal val) {
        return null;
    }

    @Override
    public String quoteGroupByFieldName(TypedVal val) {
        return null;
    }

    public static String parseMongoFieldName(String tableName, String fieldName, String baseTableAlias) {
        return Strings.isNullOrEmpty(tableName) || !Strings.isNullOrEmpty(baseTableAlias) && baseTableAlias.equals(tableName) ? fieldName : tableName + "." + fieldName;
    }







    /********************************* 2. todo *********************************/

    @Override
    public Dialect setDoQuote(boolean paramBoolean) {
        return null;
    }


    @Override
    public TypedVal setPage(TypedVal query, Long offset, Long limit) {
        return null;
    }

    @Override
    public Dialect setVersion(long majorVersion, long minorVersion) {
        return null;
    }

    @Override
    public long getMajorVersion() {
        return 0;
    }

    @Override
    public long getMinorVersion() {
        return 0;
    }

    @Override
    public Dialect setDbProVersion(String dbProVersion) {
        return null;
    }

    @Override
    public String getDbProVersion() {
        return "";
    }

    @Override
    public Dialect setDbProName(String dbProName) {
        return null;
    }

    @Override
    public String getDbProName() {
        return "";
    }

    @Override
    public String fieldAsAlias(String field, String alias) {
        return "";
    }

    @Override
    public String getEmptyTable() {
        return null;
    }

    @Override
    public boolean isAliasAmbiguousInJoin() {
        return false;
    }

    @Override
    public boolean isOffsetLimitRequiresOrderBy() {
        return false;
    }

    @Override
    public String nullsOrder(String sortStr, String direction, String nullsOrder) {
        return "";
    }

    @Override
    public String nullsOrder(String sortStr, String direction, TypedVal.EvalScope scope, String nullsOrder) {
        return "";
    }

    @Override
    public TypedVal reformCustomQuery(String customQuery) {
        return null;
    }

    @Override
    public TypedVal createTableVal(List<String> tablePath) {
        return null;
    }

    @Override
    public boolean isJsonAvailable() {
        return false;
    }

    @Override
    public boolean isBoolAvailable() {
        return false;
    }

    @Override
    public Object jodaToNativeParseFormat(String param) {
        return null;
    }

    @Override
    public Object boolToSqlLiteral(Boolean value) {
        return null;
    }
}
